<?php

	include("bd/conexao/config.php"); // Arquivo de configuração MySQL
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>	Alterar Senha </title>	

		<!-- CSS -->	
		<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
		<link href="css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
		<link href="css/docs.min.css" rel="stylesheet" type="text/css">
		<link href="css/style.css" rel="stylesheet" type="text/css">
		<link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,700,300&amp;subset=latin,cyrillic-ext,vietnamese,cyrillic" rel="stylesheet" type="text/css">

	    <!-- SCRIPTS -->
		<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
		<script src="https://code.jquery.com/jquery.js"></script>	

		<script src="js/jquery.validate.js"></script> 		
		
		<!-- Include all compiled plugins (below), or include individual files as needed -->
	    <script src="js/bootstrap.min.js"></script>

	    <script>   	  	

	    	$(document).ready(function() { 	    	 

    			/* Função Limpar Campo Senha do Formulário Alterar Senha */

	    	 	function limparCampoSenha() {
	    			
	    			$('#senha').val("");	
	    			$('#confirma_senha').val("")    			    		

    			}    	

    			$('#modalAlertaAlteraSenha #btnOK').click(function() {  			  

					$.ajax({
						url: 'scripts/limpar-sessao.php',										
						success: function(result) {							
							$(window.document.location).attr('href','index.php'); 								
						}

					});					

				});

				/* Validação Alterar Senha */

				$.validator.addMethod("valueNotEquals", function(value, element, arg){
						return arg != value;
					}, "Value must not equal arg.");		
		
				$('#form-altera-senha').validate({

					rules:{				
						
						txtSenha: 	       { required: true },	
						txtConfirmaSenha:  { equalTo:  "#senha"  },											

					},

					messages:{				
						
						txtSenha: 		  { required: "Digite a senha" },
						txtConfirmaSenha: { equalTo:  "Senha e confirmação de senha são diferentes" },																								

					},

					submitHandler: function() { 
				   		
				   		var senha = $('#senha').val();			   		

				   		$.post('scripts/altera-senha-usuario.php', 
				   		{		   			
				   			txtSenha : senha 

				   		}, function(resposta) {		   		

				        	var resultado = resposta;
				        		        		        	
				        	if (resultado == 1) {			        	    
				        		$('#modalAlertaAlteraSenha #textoAlertaAlteraSenha').html("Senha alterada com sucesso!");
								$('#modalAlertaAlteraSenha').modal('show');	

			        		}        		

				        	else {
				        		$('#modalAlertaAlteraSenha #textoAlertaAlteraSenha').html("Erro ao alterar senha!");
								$('#modalAlertaAlteraSenha').modal('show');
							
			        	    }		        	

				        });			       

			    	    return false;
			 
					}, 

					debug: true						

				});

		});

		</script>

	</head>

	<body>

		<div class="container">           

			<div class="img-logo">

				<a href="http://ibmontesiao.com" title="Igreja Batista Monte Sião"> 
		      		<img src="http://ibmontesiao.com/wp-content/login-logo.png?v=1297365009" class="center-block" />
		    	</a>						    

	    	</div>	   								
					
			<form mode="role" id="form-altera-senha" method="post">	

				<h2 class="titulo"> Alterar Senha </h2>												    
						    	  
		    	<div class="form-group">	
		    		<label for="senha">Senha</label>						    
					<input type="password" class="form-control" name="txtSenha" id="senha">				    			
				</div>

				<div class="form-group">	
					<label for="confirma_senha">Confirmação Senha</label>						    
					<input type="password" class="form-control" name="txtConfirmaSenha" id="confirma_senha">				    			
				</div>		

				<div class="form-group button">			
					<button type="submit" class="btn btn-primary" id="btnSalvar">Salvar</button>		
				</div>							

			</form>			 

	    </div> 				

	    <!-- MODAL ALERTA -->

	    <div id="modalAlertaAlteraSenha" class="modal fade">
			<div class="modal-dialog modal-sm">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			        <h3 class="modal-title text-center">Alerta</h3>
			      </div>
			      <div class="modal-body">
			        <h5 id="textoAlertaAlteraSenha"></h5>
			      </div>
			      <div class="modal-footer">			       
			        <button type="button" id="btnOK" class="btn btn-primary" data-dismiss="modal">OK</button>		        
			      </div>
			    </div><!-- /.modal-content -->
			</div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

	</body>

</html>

